import { InjectRedis } from "@nestjs-modules/ioredis";
import Redis from "ioredis";
import { Injectable } from "@nestjs/common";
import { SharedService } from "src/shared/shared.service";
import { JwtService } from "@nestjs/jwt";
import { ConfigService } from "@nestjs/config";
import { PrismaService } from "nestjs-prisma";
import * as svgCaptcha from "svg-captcha";
import { CAPTCHA_IMG_KEY } from "../../common/contants/redis.contants";

@Injectable()
export class LoginService {
    constructor(
        private readonly sharedService: SharedService,
        @InjectRedis() private readonly redis: Redis,
    ) {}

    async createImageCaptcha() {
        try {
            const { data, text } = svgCaptcha.createMathExpr({
                size: 5,
                ignoreChars: "0o1i",
                noise: 2,
                color: true,
                background: "#cc9966",
            });
            const result = { img: data.toString(), uuid: this.sharedService.generateUUID(),}
            await this.redis.set(text, `${CAPTCHA_IMG_KEY}:${result.uuid}`, 'EX', 60 * 5);
            return result; 
        } catch (error) {
            console.log(error);
        }
    }

    // 登录
    async login(username: string, password: string) {
        
    }
}